package cn.itcast.nems.studentrecord.dao.entity;

import cn.itcast.nems.common.entity.LongIdEntity;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Getter;
import lombok.Setter;

import java.time.LocalDate;

/**
 * <p>
 * 应收明细;所有对学生的收款都走应收单
 * </p>
 *
 * @author liyong
 * @since 2023-11-30
 */
@Getter
@Setter
@TableName("e2_student_record_receivable")
public class StudentRecordReceivable extends LongIdEntity {

    /**
     * 增加应收
     */
    private static final String ACCOUNT_RECEIVABLE_TYPE_IN = "IN";

    /**
     * 扣减应收
     */
    private static final String ACCOUNT_RECEIVABLE_TYPE_OUT = "OUT";

    /**
     * 学籍ID
     */
    private String studentRecordId;

    /**
     * 引用单据类型;枚举值：新报名｜ORDER、升级｜RENEWAL、转班｜TRANSFER、调价｜ADJUSTMENT。
     */
    private String referenceType;

    /**
     * 引用单据ID
     */
    private String referenceId;

    /**
     * 引用单据行ID
     */
    private String referenceLineId;

    /**
     * 应收金额;通过调价单调减金额时，此金额为负
     */
    private Integer amount;

    /**
     * 业务实际发生日期;补录单据时可能会发生单据录入日期和业务实际发生日期不一致的情况。
     */
    private LocalDate bizDate;

    /**
     * 应收类型，IN：代表增加应收，OUT：代表扣减应收
     */
    private String accountReceivableType = ACCOUNT_RECEIVABLE_TYPE_IN;

    public void setAmount(Integer amount) {
        this.amount = amount;
        if (amount != null && amount < 0) {
            this.accountReceivableType = ACCOUNT_RECEIVABLE_TYPE_OUT;
        }else{
            this.accountReceivableType = ACCOUNT_RECEIVABLE_TYPE_IN;
        }
    }
}
